#ifndef UTILS_H
#define UTILS_H


#include <string>
#include <iostream>
#include "msg_topic.h"


class Timera
{
public:
    Timera() : beg_(clock_::now())
    {}
    
    void reset()
    {
        beg_ = clock_::now();
    }

    double elapsed() const
    {
        return std::chrono::duration_cast<second_>(clock_::now() - beg_).count();
    }

    void out(std::string message = "")
    {
        double t = elapsed();
        // std::cout << message << " elapsed time: " << t << " ms" << std::endl;
        LOG_I("{}elapse time {} ms", message, t);
        reset();
    }

    double get_duration() const
    {
        return elapsed();
    }

private:
    typedef std::chrono::high_resolution_clock clock_;
    typedef std::chrono::duration<double, std::milli> second_;
    std::chrono::time_point<clock_> beg_;
};

class Utils 
{
private:
    std::string name; // 实例属性

public:
    // 构造函数
    Utils(const std::string& name);

    // 打印实例相关信息
    void printName() const;

    // 静态方法
    static void log(const std::string& message);

    // 静态方法访问类信息
    static void printClassInfo();
};

#endif // UTILS_H

